package org.tagging.service.impl.other;

import org.springframework.stereotype.Service;
import org.tagging.dao.TaggingAuthorityMapper;
import org.tagging.dao.TaggingUserAuthorityMapper;
import org.tagging.model.TaggingAuthority;
import org.tagging.model.TaggingAuthorityExample;
import org.tagging.model.TaggingUserAuthority;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class AuthorityServiceImpl {
    @Resource
    private TaggingAuthorityMapper authorityMapper;



    public List<TaggingAuthority> retrieveAuthoritiesByRoleId(Integer role, TaggingAuthority.Column... columns) {
        TaggingAuthorityExample example = new TaggingAuthorityExample();
        TaggingAuthorityExample.Criteria criteria = example.createCriteria();
        criteria.andRoleIdEqualTo(role);
        return authorityMapper.selectByExampleSelective(example, columns);
    }

    public List<TaggingAuthority> queryByRoleId(Integer roleId, TaggingAuthority.Column... columns) {
        TaggingAuthorityExample example = new TaggingAuthorityExample();
        TaggingAuthorityExample.Criteria criteria = example.createCriteria();
        criteria.andRoleIdEqualTo(roleId);
        return authorityMapper.selectByExampleSelective(example, columns);
    }

    public List<String> queryAllAuthorities(TaggingAuthority.Column... columns) {
        TaggingAuthorityExample example = new TaggingAuthorityExample();
        List<TaggingAuthority> taggingAuthorities = authorityMapper.selectByExampleSelective(example, columns);
        List<String> aus = new ArrayList<>(taggingAuthorities.size());
        taggingAuthorities.forEach(taggingAuthority -> aus.add(taggingAuthority.getAuthority()));
        return aus;
    }
}
